from django.views import View
from django.http import JsonResponse
import csv
from django.http import HttpResponse
import logging
import datetime

logger = logging.getLogger('log')

class TestView(View):
    def get(self, request):
        pass

    def post(self, request):
        pass

class IndexView(View):
    def get(self, request):
        logger.debug("my-django-debug--------------debug1-")
        logger.info("my-django-error---------------info1-")
        logger.error("my-django-error--------------error1-")
        logger.warning("my-django-error-waring1-")
        logger.warning("my-django-error-waring2-")
        logger.warning("my-django-error-waring3-")
        logger.error(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        # logger.exception("excep: xxxx")
        
        return JsonResponse(data={"msg": "hello world"})
    
    def post(self, request):
        response = HttpResponse(
            content_type="text/csv",
            headers={"Content-Disposition": 'attachment; filename="somefilename.csv"'},
        )

        writer = csv.writer(response)
        writer.writerow(["First row", "Foo", "Bar", "Baz"])
        writer.writerow(["Second row", "A", "B", "C", '"Testing"', "Here's a quote"])

        return response

import csv
class UploadView(View):
    def post(self, request):
        csvfile = request.FILES['files']
        decoded_file = csvfile.read().decode('utf-8')  
        reader = csv.reader(decoded_file.splitlines())  
        for row in reader:
            print(row)
        return JsonResponse(data={"msg": "hello world"})
